Bug 5560

Bug Description:

This is a deadlock.
The following is an example of deadlock thread dump:

"Thread-2": waiting to lock monitor 0x0000000008e0e518 (object 0x00000000ec2a0390, 
a org.apache.derby.client.am.LogicalConnection), which is held by "Thread-1"
"Thread-1": waiting to lock monitor 0x0000000008e0bc88 (object 0x00000000ec2a0330,
a org.apache.derby.client.ClientXAConnection40$$EnhancerByMockitoWithCGLIB$$fa0b2c9e), which is held by "Thread-2"

Java stack information for the threads listed above:
===================================================
"Thread-2":
at org.apache.derby.client.am.LogicalConnection.nullPhysicalConnection(LogicalConnection.java:64)
- waiting to lock <0x00000000ec2a0390> (a org.apache.derby.client.am.LogicalConnection) at org.apache.derby.client.ClientPooledConnection.close(ClientPooledConnection.java:204) - locked <0x00000000ec2a0330> (a org.apache.derby.client.ClientXAConnection40$$EnhancerByMockitoWithCGLIB$$fa0b2c9e) at org.apache.derby.client.ClientXAConnection.close(ClientXAConnection.java:132) - locked <0x00000000ec2a0330> (a org.apache.derby.client.ClientXAConnection40$$EnhancerByMockitoWithCGLIB$$fa0b2c9e) at org.apache.derby.client.ClientXAConnection40$$EnhancerByMockitoWithCGLIB$$fa0b2c9e.CGLIB$close$4()
at org.apache.derby.client.ClientXAConnection40$$EnhancerByMockitoWithCGLIB$$fa0b2c9e$$FastClassByMockitoWithCGLIB$$9a2a041b.invoke()
at org.mockito.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:216)
at org.mockito.internal.creation.AbstractMockitoMethodProxy.invokeSuper(AbstractMockitoMethodProxy.java:10)
at org.mockito.internal.invocation.realmethod.CGLIBProxyRealMethod.invoke(CGLIBProxyRealMethod.java:22)
at org.mockito.internal.invocation.realmethod.FilteredCGLIBProxyRealMethod.invoke(FilteredCGLIBProxyRealMethod.java:27)
at org.mockito.internal.invocation.InvocationImpl.callRealMethod(InvocationImpl.java:108)
at org.mockito.internal.stubbing.answers.CallsRealMethods.answer(CallsRealMethods.java:36)
at org.mockito.internal.stubbing.StubbedInvocationMatcher.answer(StubbedInvocationMatcher.java:34)
at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:91)
at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:38)
at org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodInterceptorFilter.java:51)
at org.apache.derby.client.ClientXAConnection40$$EnhancerByMockitoWithCGLIB$$fa0b2c9e.close()
at Derby5560$Thread2.run(Derby5560.java:70)

"Thread-1":
at org.apache.derby.client.ClientPooledConnection.recycleConnection(ClientPooledConnection.java:353)
- waiting to lock <0x00000000ec2a0330> (a org.apache.derby.client.ClientXAConnection40$$EnhancerByMockitoWithCGLIB$$fa0b2c9e) at org.apache.derby.client.ClientXAConnection40$$EnhancerByMockitoWithCGLIB$$fa0b2c9e.CGLIB$recycleConnection$11()
at org.apache.derby.client.ClientXAConnection40$$EnhancerByMockitoWithCGLIB$$fa0b2c9e$$FastClassByMockitoWithCGLIB$$9a2a041b.invoke()
at org.mockito.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:216)
at org.mockito.internal.creation.AbstractMockitoMethodProxy.invokeSuper(AbstractMockitoMethodProxy.java:10)
at org.mockito.internal.invocation.realmethod.CGLIBProxyRealMethod.invoke(CGLIBProxyRealMethod.java:22)
at org.mockito.internal.invocation.realmethod.FilteredCGLIBProxyRealMethod.invoke(FilteredCGLIBProxyRealMethod.java:27)
at org.mockito.internal.invocation.InvocationImpl.callRealMethod(InvocationImpl.java:108)
at org.mockito.internal.stubbing.answers.CallsRealMethods.answer(CallsRealMethods.java:36)
at org.mockito.internal.stubbing.StubbedInvocationMatcher.answer(StubbedInvocationMatcher.java:34)
at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:91)
at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:38)
at org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodInterceptorFilter.java:51)
at org.apache.derby.client.ClientXAConnection40$$EnhancerByMockitoWithCGLIB$$fa0b2c9e.recycleConnection()
at org.apache.derby.client.am.LogicalConnection.close(LogicalConnection.java:91)
- locked <0x00000000ec2a0390> (a org.apache.derby.client.am.LogicalConnection) at Derby5560$Thread1.run(Derby5560.java:47)
More details about this bug are at DERBY-5560 JIRA page.

How To Reproduce:

This bug is reproduced under derby 10.5.1.1 and JDK 1.6.0_33 and JDK 1.7.0_25.
Execute the following scripts to run the test to reproduce the bug (assume the location of the derby test project is derby_test_home).

Linux:
${derby_test_home}/scripts/5560.sh [--monitoroff]
Windows:
%derby_test_home%\scripts\5560.bat [--monitoroff]

Example: Use monitor to report and terminate the program when deadlock happens:
${derby_test_home}/scripts/5560.sh


Turn off monitor:
${derby_test_home}/scripts/5560.sh --monitoroff

Option Function
--monitoroff, -mo Turn off to stop reporting bug messages and ending program when test
runs into the expected concurrency bug which is a deadlock.
User has to terminate the program manually when this option is set.